package com.example.demo.controller

import com.example.demo.service.UploadService
import com.example.demo.utils.MResult
import com.example.demo.vo.UploaFileVo
import io.swagger.annotations.Api
import io.swagger.annotations.ApiOperation
import io.swagger.annotations.ApiSort
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile


@RestController
@RequestMapping("/upload")
@Api(tags = ["上传接口"])
@ApiSort(value = 3)
class UploadController(
    private val uploadService: UploadService
) {

    @ApiOperation(value = "上传图片")
    @PostMapping("/image")
    fun guploadImage(file: MultipartFile): MResult<UploaFileVo>? {
        uploadService.uploadImage(file)?.let {
            return  MResult<UploaFileVo>().result(it)
        }?: return MResult<UploaFileVo>().error("上传失败")
    }

    @ApiOperation(value = "上传视频")
    @PostMapping("/video")
    fun guploadVideo(file: MultipartFile): MResult<UploaFileVo>? {
        uploadService.uploadVideo(file)?.let {
            return  MResult<UploaFileVo>().result(it)
        }?: return MResult<UploaFileVo>().error("上传失败")
    }


}